package com.tarena.lbs.basic.web.repository;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tarena.lbs.basic.web.mapper.StoreMapper;
import com.tarena.lbs.pojo.basic.entity.StoreSearchEntity;
import com.tarena.lbs.pojo.basic.po.StorePO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class StoreRepository extends ServiceImpl<StoreMapper, StorePO> {
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private StoreESRepository storeESRepository;
    public void saveData(StorePO storePO) {
        //封装完整数据写入到持久层
        storeMapper.insert(storePO);
        //todo 写入到es
        StoreSearchEntity entity = new StoreSearchEntity();
        BeanUtils.copyProperties(storePO,entity);
        entity.setLocation(storePO.getStoreLatitude()+","+storePO.getStoreLongitude());
        storeESRepository.save(entity);
    }
}
